package com.runjian.rundo.iot.agent.iec104.action.impl;

import com.runjian.rundo.iot.agent.common.message.DeviceMessage;
import org.springframework.stereotype.Component;

import com.runjian.rundo.iot.agent.iec104.action.AbstractActionHandle;
import com.runjian.rundo.iot.agent.iec104.cache.ScheduleTaskCache;
import com.runjian.rundo.iot.agent.iec104.consts.Action;
import com.runjian.rundo.iot.agent.iec104.enums.UFrameControlType;
import com.runjian.rundo.iot.agent.iec104.parser.frame.UIec104Frame;
import com.runjian.rundo.iot.agent.iec104.session.Iec104TcpClientDeviceSession;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 开始任务
 *
 * @author CaoQingHua
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class StartTaskActionHandle extends AbstractActionHandle {

    private final ScheduleTaskCache scheduleTaskCache;

    @Override
    public Action getAction() {
        return Action.START_TASK;
    }

    @Override
    public void handle(DeviceMessage deviceMessage, Iec104TcpClientDeviceSession iec104DeviceSession) {
        // 组装初始化字符,开始进行程序启动
        UIec104Frame uIec104Frame = new UIec104Frame();
        uIec104Frame.setFunction(UFrameControlType.STARTDT_C);
        // 写入U侦数据
        iec104DeviceSession.writeUAndFlush(uIec104Frame);
    }
}
